package com.warm.orm.extension;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import com.easy.query.core.basic.extension.logicdel.LogicDeleteBuilder;
import com.easy.query.core.basic.extension.logicdel.abstraction.AbstractLogicDeleteStrategy;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.parser.core.base.ColumnSetter;
import com.easy.query.core.expression.parser.core.base.WherePredicate;

/**
 * @author 胡高
 * @date 2023/11/02
 */
public class DeleteFlagStrategy extends AbstractLogicDeleteStrategy {
    public static final String STRATEGY_NAME = "DELETE_FLAG_STRATEGY";

    private static final Set<Class<?>> allowedPropertyTypes = new HashSet<>(Arrays.asList(String.class));

    @Override
    public Set<Class<?>> allowedPropertyTypes() {
        return allowedPropertyTypes;
    }

    @Override
    protected SQLExpression1<ColumnSetter<Object>> getDeletedSQLExpression(LogicDeleteBuilder builder, String propertyName) {
        return o -> o.set(propertyName, "2");
    }


    @Override
    protected SQLExpression1<WherePredicate<Object>> getPredicateFilterExpression(LogicDeleteBuilder builder, String propertyName) {
        return o -> o.eq(propertyName, "0");
    }

    @Override
    public String getStrategy() {
        return DeleteFlagStrategy.STRATEGY_NAME;
    }
}
